package com.ruoyi.web.controller.fantasy;

import java.util.List;

import com.huanzhidadi.fantasy.bean.domain.FantasyNpcTalk;
import com.huanzhidadi.fantasy.bean.domain.FantasyTask;
import com.ruoyi.fantasy.domain.FantasyNpc;
import com.ruoyi.fantasy.service.IFantasyNpcService;
import com.ruoyi.fantasy.service.IFantasyTaskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fantasy.service.IFantasyNpcTalkService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * fantasynpc语句Controller
 * 
 * @author wanghui
 * @date 2020-10-16
 */
@Controller
@RequestMapping("/fantasy/talk")
public class FantasyNpcTalkController extends BaseController
{
    private String prefix = "fantasy/fantasyTalk";

    @Autowired
    private IFantasyNpcTalkService fantasyNpcTalkService;

    @Autowired
    private IFantasyNpcService fantasyNpcService;

    @Autowired
    private IFantasyTaskService fantasyTaskService;

    @RequiresPermissions("fantasy:talk:view")
    @GetMapping()
    public String talk()
    {
        return prefix + "/talk";
    }

    /**
     * 查询fantasynpc语句列表
     */
    @RequiresPermissions("fantasy:talk:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FantasyNpcTalk fantasyNpcTalk)
    {
        startPage();
        List<FantasyNpcTalk> list = fantasyNpcTalkService.selectFantasyNpcTalkList(fantasyNpcTalk);
        return getDataTable(list);
    }

    /**
     * 导出fantasynpc语句列表
     */
    @RequiresPermissions("fantasy:talk:export")
    @Log(title = "fantasynpc语句", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FantasyNpcTalk fantasyNpcTalk)
    {
        List<FantasyNpcTalk> list = fantasyNpcTalkService.selectFantasyNpcTalkList(fantasyNpcTalk);
        ExcelUtil<FantasyNpcTalk> util = new ExcelUtil<FantasyNpcTalk>(FantasyNpcTalk.class);
        return util.exportExcel(list, "talk");
    }

    /**
     * 新增fantasynpc语句
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        List<FantasyNpc> list = fantasyNpcService.selectFantasyNpcList(null);
        mmap.put("fantasyNpcList", list);
        List<FantasyTask> fantasyTaskList = fantasyTaskService.selectFantasyTaskList(null);
        mmap.put("fantasyTaskList", fantasyTaskList);

        return prefix + "/add";
    }

    /**
     * 新增保存fantasynpc语句
     */
    @RequiresPermissions("fantasy:talk:add")
    @Log(title = "fantasynpc语句", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FantasyNpcTalk fantasyNpcTalk)
    {
        return toAjax(fantasyNpcTalkService.insertFantasyNpcTalk(fantasyNpcTalk));
    }

    /**
     * 修改fantasynpc语句
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        FantasyNpcTalk fantasyNpcTalk = fantasyNpcTalkService.selectFantasyNpcTalkById(id);
        mmap.put("fantasyNpcTalk", fantasyNpcTalk);
        List<FantasyNpc> list = fantasyNpcService.selectFantasyNpcList(null);
        mmap.put("fantasyNpcList", list);
        List<FantasyTask> fantasyTaskList = fantasyTaskService.selectFantasyTaskList(null);
        mmap.put("fantasyTaskList", fantasyTaskList);
        return prefix + "/edit";
    }

    /**
     * 修改保存fantasynpc语句
     */
    @RequiresPermissions("fantasy:talk:edit")
    @Log(title = "fantasynpc语句", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FantasyNpcTalk fantasyNpcTalk)
    {
        return toAjax(fantasyNpcTalkService.updateFantasyNpcTalk(fantasyNpcTalk));
    }

    /**
     * 删除fantasynpc语句
     */
    @RequiresPermissions("fantasy:talk:remove")
    @Log(title = "fantasynpc语句", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fantasyNpcTalkService.deleteFantasyNpcTalkByIds(ids));
    }
}
